package com.buydeem.share.hystrixdemo.service;

import com.buydeem.share.hystrixdemo.model.User;
import lombok.extern.slf4j.Slf4j;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author zengchao
 * @version 1.0.0
 * @ClassName UserService.java
 * @Description TODO
 * @createTime 2021年03月29日 20:48:00
 */
@Slf4j
public class UserService {
    private Map<String, User> userMap = new HashMap<>();

    public UserService() {
        userMap.put("mac",new User("mac",18,"男"));
        userMap.put("tom",new User("tom",19,"男"));
        userMap.put("jack",new User("jack",17,"男"));
    }

    public User queryUser(String name){
        log.info("query params:{}",name);
        return userMap.get(name);
    }

    public List<User> queryUsers(List<String> names){
        log.info("batch query params:{}",names);
        return userMap.entrySet().stream()
                .filter(e -> names.contains(e.getKey()))
                .map(Map.Entry::getValue)
                .collect(Collectors.toList());
    }
}
